package itypes

import (
	"github.com/hwcer/cosgo/times"
	"github.com/hwcer/logger"
	"github.com/hwcer/updater"
	"github.com/hwcer/updater/dataset"
	"server/game/model"
	"server/share/config"
)

var Daily = dailyIType{}

func init() {
	Daily.IType = *NewIType(config.ITypeDaily)
	im := &model.Daily{}
	if err := updater.Register(updater.ParserTypeDocument, updater.RAMTypeAlways, im, &Daily); err != nil {
		logger.Panic(err)
	}
}

type dailyIType struct {
	IType
}

func (this *dailyIType) Handle(u *updater.Updater) *DailyHandle {
	doc := u.Handle(config.ITypeDaily).(*updater.Document)
	return &DailyHandle{Document: doc}
}
func (this *dailyIType) ObjectId(u *updater.Updater, _ int32) string {
	iid, _ := times.New(u.Now()).Sign(0)
	return model.Unique(u, iid)
}

type DailyHandle struct {
	*updater.Document
}

func (this *DailyHandle) All() *model.Daily {
	return this.Document.Any().(*model.Daily)
}

func (this *DailyHandle) GetInt32(k any) int32 {
	v := this.Document.Get(k)
	return dataset.ParseInt32(v)
}
func (this *DailyHandle) GetInt64(k any) int64 {
	v := this.Document.Get(k)
	return dataset.ParseInt64(v)
}
